package pod

import (
	"context"
	"fmt"

	"go-pod/api/internal/svc"
	"go-pod/api/internal/types"
	"go-pod/pod-rpc/pod"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeletePodcastLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDeletePodcastLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeletePodcastLogic {
	return &DeletePodcastLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DeletePodcastLogic) DeletePodcast(req *types.PodDeleteReq) (resp *types.PodDeleteResp, err error) {

	// 调用RPC服务删除播客
	_, err = l.svcCtx.PodRpcClient.DeletePodcast(l.ctx, &pod.DeletePodcastReq{
		Id: req.Id,
	})
	if err != nil {
		l.Logger.Errorf("删除播客失败: %v", err)
		return nil, fmt.Errorf("删除播客失败，请稍后重试")
	}

	// 记录成功日志
	l.Logger.Infof("播客删除成功，ID: %d", req.Id)

	return &types.PodDeleteResp{}, nil
}
